import type { PageResult } from '#/type/base_beans';
import type { SysPostReq, SysPostResp } from '#/type/sys_post';

import { requestClient } from '#/api/request';

const API_PREFIX = '/sys/post';

export async function getPostByIdApi(id: string) {
  return requestClient.get<SysPostResp>(`${API_PREFIX}/get_by_id/${id}`);
}

export async function getPostListByIdsApi(ids: Array<string>) {
  return requestClient.get<Array<SysPostResp>>(`${API_PREFIX}/get_by_ids`, {
    params: { ids },
  });
}

export async function getPostListApi(params: SysPostReq) {
  return requestClient.get<Array<SysPostResp>>(`${API_PREFIX}/list`, {
    params,
  });
}

export async function getPostPageApi(params: SysPostReq) {
  return requestClient.get<PageResult<SysPostResp>>(`${API_PREFIX}/page`, {
    params,
  });
}

export async function createPostApi(data: SysPostReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create`, data);
}

export async function editPostApi(data: SysPostReq) {
  return requestClient.put<Promise<void>>(`${API_PREFIX}/edit`, data);
}

export async function createEditPostApi(data: SysPostReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create_edit`, data);
}

export async function deletePostApi(ids: Array<string>) {
  return requestClient.delete<Promise<void>>(`${API_PREFIX}/delete`, {
    params: { ids },
  });
}
